<template>
<div class="container">
    <div class="top-title">
        <h1 class="title">系统简介</h1>
        <el-button type="NewlyBuild" @click="iftrue=true" icon="el-icon-plus" v-if="_SHOWBTN('wzgl-xtjj-xj')">新建</el-button>
    </div>
    <div class="secretary mtb-10" v-for="(item,index) in BriefList " :key="item.id">
        <div class="secretary-box">
            <div class="box-title">分类标签:</div>
            <el-input v-model="item.tip" :disabled="index !== editIndex" maxlength="50" show-word-limit type="text"></el-input>
        </div>
        <!--文本框-->
        <div class="text-box">
            <h1 class="text-title">具体阐述：</h1>
            <el-input type="textarea" placeholder="请输入分类标签的具体阐述" v-model="item.content" maxlength="200" show-word-limit :disabled="index !== editIndex"></el-input>
        </div>
        <el-row>
            <el-button type="edit" @click="setIndex(index)" :disabled="index === editIndex" v-if="_SHOWBTN('wzgl-xtjj-xg')">编辑</el-button>
            <el-button type="preservation" @click="Save(item.id,item.tip,item.content)" :disabled="index !== editIndex" v-if="_SHOWBTN('wzgl-xtjj-xg')">保存</el-button>
            <Single-deletion :clearOne="clearOne" :id="item.id" showBetCode="wzgl-xtjj-sc"></Single-deletion>
        </el-row>
    </div>

    <!--新建按钮点击展示区-->
    <div class="secretary mtb-10" v-if="iftrue">
        <div class="secretary-box">
            <div class="box-title">分类标签:</div>
            <el-input v-model="inputPost1" :disabled="disabled" placeholder="请输入分类标签" maxlength="50" show-word-limit type="text"></el-input>
        </div>
        <!--文本框-->
        <div class="text-box">
            <h1 class="text-title">具体阐述：</h1>
            <el-input type="textarea" placeholder="请输入分类标签的具体阐述" v-model="inputPost2" maxlength="200" show-word-limit :disabled="disabled"></el-input>
        </div>
        <el-row>
            <el-button type="edit" @click="disabled=false" :disabled="!disabled">编辑</el-button>
            <el-button type="preservation" @click="SaveNew" :disabled="disabled">保存</el-button>
            <el-popover placement="top" width="166" v-model="visible">
                <p class="clear-one">是否要删除此行？</p>
                <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="visible = false">取消</el-button>
                    <el-button type="primary" size="mini" @click="clear">确定</el-button>
                </div>
                <el-button slot="reference" type="SingleDeletionev">删除</el-button>
            </el-popover>
        </el-row>
    </div>
</div>
</template>

<script>
import NewlyBuild from "@/components/Popup/NewlyBuild";
import SingleDeletion from "@/components/Popup/SingleDeletion";

export default {
    components: {
        NewlyBuild,
        SingleDeletion,
    },
    data() {
        return {
            visible: false,
            //控制新建是否出现
            iftrue: false,
            //控制输入框是否可编辑
            disabled: false,
            inputPost1: "",
            inputPost2: "",
            BriefList: [],
            editIndex: -1,
        };
    },
    created() {
        //   调用系统简介列表接口
        this.GetBriefList();
    },
    methods: {
        //编辑事件
        setIndex(index) {
            this.editIndex = index;
        },
        //调用系统简介列表接口
        GetBriefList() {
            this.Api.getBriefList().then((res) => {
                this.BriefList.length = 0;
                this.BriefList = res.data;
                // for(item of this.BriefList ){
                //   this.ifTrueList.push({disabled:true})
                // }
                // console.log(this.ifTrueList,1212)
                // console.log(this.BriefList,111)
            });
        },
        //报春的接口，按钮
        Save(id, tip, content) {
            this.editIndex = -1;
            // console.log(id)
            // console.log(tip)
            // console.log(content)
            this.Api.getBriefSavue({
                content: content,
                id: id,
                tip: tip,
            }).then((res) => {
                // console.log(res,111)
                if (res.code === "0") {
                    // console.log(111)
                    // this.disabled = true;
                    this.editIndex = -1;
                }
            });
        },
        //删除的接口
        clearOne(id) {
            this.Api.getBriefRemove({
                id: id
            }).then((res) => {
                // console.log(res,111)
                this.GetBriefList();
            });
        },
        //新增加
        SaveNew() {
            this.Api.getBriefSavueNew({
                content: this.inputPost2,
                tip: this.inputPost1,
            }).then((res) => {
                if (res.code === "0") {
                    this.disabled = true;
                    this.iftrue = false;
                    this.inputPost1 = "";
                    this.inputPost2 = "";
                    // console.log(res,111)
                    this.GetBriefList();
                }
            });
        },
        //新建删除
        clear() {
            this.visible = false;
            this.iftrue = false;
            this.inputPost1 = "";
            this.inputPost2 = "";
        },
    },
};
</script>

<style lang="less" scoped>
.secretary {
    background: rgba(248, 248, 249, 1);
    padding: 30px 0 20px 40px;

    .secretary-box {
        display: flex;
        align-items: center;
        margin-bottom: 20px;

        .box-title {
            width: 74px;
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: rgba(51, 51, 51, 1);
        }

        .el-input {
            width: 360px;
        }

        /deep/.el-input__inner {
            width: 360px;
            height: 36px;
            border-radius: 2px;
            border: 1px solid rgba(221, 221, 221, 1);
        }
    }

    /deep/.el-row {
        margin-left: 70px;
        display: flex;

        .el-button--edit {
            width: 60px;
            height: 28px;
            background: rgba(255, 255, 255, 1);
            border-radius: 4px;
            border: 1px solid rgba(221, 221, 221, 1);
            padding: 0;
            color: #333333;
            margin-right: 11px;
        }

        .el-button--preservation {
            width: 60px;
            height: 28px;
            background: rgba(255, 255, 255, 1);
            border-radius: 4px;
            border: 1px solid rgba(221, 221, 221, 1);
            padding: 0;
            color: #333333;
            margin-right: 20px;
        }
    }
}

.mtb-10 {
    margin: 20px 0 20px 0;
}

.mb-20 {
    margin-bottom: 20px;
}

.height-190 {
    height: 190px;
}

/deep/.el-button--newlyBuild {
    width: 60px;
    height: 28px;
    background: rgba(61, 127, 255, 1) !important;
    border-radius: 4px;
    padding: 0;
    color: #ffffff !important;
}

.top-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 1px solid #f0f2f5;
}

/deep/.el-button--NewlyBuild {
    margin-right: 0px !important;
}

/*文本框*/

.text-box {
    display: flex;
    margin-bottom: 20px;

    .text-title {
        width: 75px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(51, 51, 51, 1);
        line-height: 20px;
    }

    /deep/.el-textarea {
        max-width: 810px;
        min-height: 100px;
    }

    /deep/.el-textarea__inner {
        max-width: 810px;
        min-height: 100px !important;
    }
}

/deep/.el-button--NewlyBuild {
    width: 80px;
    height: 36px;
    background: rgba(61, 127, 255, 1);
    border-radius: 3px;
    padding: 0;
    color: white;
    margin-right: 10px !important;
}

/deep/.el-button--SingleDeletionev {
    width: 60px;
    height: 28px;
    background: rgba(251, 54, 63, 1);
    border-radius: 4px;
    color: white;
    padding: 0;
}

/deep/.el-input__inner {
    color: #333333 !important;
}

/deep/.el-textarea__inner {
    color: #333333 !important;
}

.el-row {
    .is-disabled {
        background-color: #F8F8F9 !important;
    }
}
</style>
